package com.aspose.cells;

import java.io.IOException;
import java.io.OutputStream;

class zcga extends OutputStream {
   protected zcgb a;
   protected int b;
   protected int c;
   protected byte[] d;
   protected byte[] e;
   protected boolean f;
   protected OutputStream g;

   public zcga(OutputStream var1, int var2) {
      this(var1, var2, false);
   }

   public zcga(OutputStream var1, int var2, boolean var3) {
      this.a = new zcgb();
      this.b = 512;
      this.c = 0;
      this.d = new byte[this.b];
      this.e = new byte[1];
      this.g = var1;
      this.a.b(var2, var3);
      this.f = true;
   }

   public void write(int b) throws IOException {
      this.e[0] = (byte)b;
      this.write(this.e, 0, 1);
   }

   public void write(byte[] b, int off, int len) throws IOException {
      if (len != 0) {
         this.a.a = b;
         this.a.b = off;
         this.a.c = len;

         do {
            this.a.e = this.d;
            this.a.f = 0;
            this.a.g = this.b;
            int var4;
            if (this.f) {
               var4 = this.a.b(this.c);
            } else {
               var4 = this.a.a(this.c);
            }

            if (var4 != 0) {
               throw new IOException((this.f ? "de" : "in") + "flating: " + this.a.i);
            }

            this.g.write(this.d, 0, this.b - this.a.g);
         } while(this.a.c > 0 || this.a.g == 0);

      }
   }

   public void a() throws IOException {
      do {
         this.a.e = this.d;
         this.a.f = 0;
         this.a.g = this.b;
         int var1;
         if (this.f) {
            var1 = this.a.b(4);
         } else {
            var1 = this.a.a(4);
         }

         if (var1 != 1 && var1 != 0) {
            throw new IOException((this.f ? "de" : "in") + "flating: " + this.a.i);
         }

         if (this.b - this.a.g > 0) {
            this.g.write(this.d, 0, this.b - this.a.g);
         }
      } while(this.a.c > 0 || this.a.g == 0);

      this.flush();
   }

   public void b() {
      if (this.a != null) {
         if (this.f) {
            this.a.b();
         } else {
            this.a.a();
         }

         this.a.d();
         this.a = null;
      }
   }

   public void close() throws IOException {
      try {
         this.a();
      } catch (IOException var5) {
         ;
      } finally {
         this.b();
         this.g.close();
         this.g = null;
      }

   }

   public void flush() throws IOException {
      this.g.flush();
   }
}
